package com.wxy.demo.dao;

import com.wxy.demo.entity.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/***
 * <p>
 * Description: 描述
 * </p>
 * @author wangxiaoyuan
 * 2021年12月08日
 */
@Repository
public interface PermissionRepository extends JpaRepository<Permission, Long> {
    @Query("SELECT p FROM Permission p LEFT JOIN RolePermission rp ON rp.permissionId = p.id LEFT JOIN Role r ON r.id = rp.roleId LEFT JOIN UserRole ur ON ur.roleId = r.id LEFT JOIN User u ON u.id = ur.userId WHERE u.id = :userId GROUP BY p.code")
    List<Permission> findAllByUserId(Long userId);
}
